package channel

import (
	"context"

	v1 "caas-platform-payment/api/channel/v1"
	"caas-platform-payment/internal/consts"
	"caas-platform-payment/internal/dao"

	"github.com/gogf/gf/v2/errors/gerror"
)

func (c *ControllerV1) Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error) {
	// return nil, gerror.NewCode(gcode.CodeNotImplemented)
	// tenantCode := ctx.Value(consts.TokenClaims.TenantCode).(string)
	cls := dao.PayChannel.Columns()
	rs, err := dao.PayChannel.Ctx(ctx).Where(cls.Id, req.Id).Delete()
	if err != nil {
		l.Error(ctx, err)
		return nil, gerror.NewCode(consts.DeleteFailed)
	}
	res = &v1.DeleteRes{}
	if res.Rows, err = rs.RowsAffected(); err != nil {
		l.Error(ctx, err)
		return nil, gerror.NewCode(consts.DeleteFailed)
	}
	return res, nil
}
